const express = require("express");
const query = require("../sql/mysql");
const {
    create,
    verify
} = require("./token");
const Router = express.Router();
//登录
Router.post("/admin/login", express.urlencoded(), async(req, res) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,PATCH,POST,GET,DELETE,OPTIONS");
    let username = req.body.username;
    let password = req.body.password;
    let sql = `SELECT * FROM admin WHERE username='${username}'`;
    let data = await query(sql);
    let obj = {}
    if (data.length != 0) {
        if (password == data[0].password) {
            obj.msg = "登录成功";
            obj.id = data[0].id;
            obj.token = create(password);
        } else {
            obj.msg = "密码错误"
        }
    } else {
        obj.msg = "用户名不存在，请先注册"
    }
    res.send(obj);
});
//核对token
Router.get("/admin/checktoken", async(req, res) => {
    let token = req.query.token;
    let result = verify(token)
    let obj = {};
    if (result) {
        obj.msg = "可以登录";
    } else {
        obj.msg = "不可以登录";
    }
    res.send(obj);
});
//检查密码是否正确
Router.get("/admin/checkpwd", async(req, res) => {
    let id = req.query.id;
    let password = req.query.password;
    let sql = `SELECT * FROM admin WHERE id='${id}'`;
    let data = await query(sql);
    let obj = {};

    if (data[0].password == password) {
        obj = {
            msg: "密码正确"
        }
    } else {
        obj = {
            msg: "密码错误"
        }
    }
    res.send(obj);
});
//删除数据
Router.delete("/admin/delgoods", express.urlencoded(), express.json(), async(req, res) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,PATCH,POST,GET,DELETE,OPTIONS");
    let good_id = req.body.good_id;
    let obj = {}
    let sql = `DELETE FROM goods WHERE good_id=${good_id}`;
    let data = await query(sql);
    if (data.affectedRows != 0) {
        obj.msg = "删除成功"
    } else {
        obj.msg = "删除失败"
    }
    res.send(obj);
});
//添加数据
Router.post("/admin/adddata", express.urlencoded(), async(req, res) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,PATCH,POST,GET,DELETE,OPTIONS");
    let src = req.body.src;
    let title = req.body.title;
    let price = req.body.price;
    let name = req.body.name;
    let tag = req.body.tag;
    let commentCount = req.body.commentCount;
    let obj = {};
    let sql = `INSERT INTO goods (good_id, src, title, price, name, tag, commentCount) 
      VALUES (null, '${src}', '${title}', ${price}, '${name}', '${tag}', '${commentCount}')`
    let data = await query(sql);
    if (data.affectedRows) {
        obj.msg = "添加成功"
    }
    res.send(obj)
});
//获取数据
Router.post("/admin/data", express.urlencoded(), async(req, res) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,PATCH,POST,GET,DELETE,OPTIONS");
    let arr = [{
        "name": "Apple iPhone 11 Pro 全网通 金色 64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200102105151196.jpg",
        "price": "7899",
        "title": "【Pro 如其名】突破性的三摄系统，A13仿生实时处理",
        "commentCount": 1290,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"后置三摄\",\"标配18W快充\"]"
    }, {
        "name": "Apple iPhone 11 全网通 白色 64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200103110129996.jpg",
        "price": "5199",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 Pro Max 全网通版 深空灰色 64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200107174237577.jpg",
        "price": "8799",
        "title": "【Pro 如其名】突破性的三摄系统，A13仿生实时处理",
        "commentCount": 2196,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"后置三摄\",\"标配18W快充\"]"
    }, {
        "name": "Apple iPhone 8 Plus 双网通版 金色 64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200102105103597.jpg",
        "price": "3499",
        "title": "【火热销售】视网膜高清显示屏,无线充电,A11仿生处理器",
        "commentCount": 159,
        "tag": "[\"原彩显示\",\"后置双摄\",\"触控ID\"]"
    }, {
        "name": "苹果 AirPods 2代 蓝牙无线耳机 白色 配有线充电盒版 ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200102104204014.jpg",
        "price": "1099",
        "title": "【火热销售】支持嘿 Siri，全新的 Apple H1 耳机芯片",
        "commentCount": 3957,
        "tag": "[\"自动开启\",\"自动连接\",\"无线\"]"
    }, {
        "name": "Apple iPhone 11 全网通 黑色 64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191209195324785.jpg",
        "price": "5260",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 紫色 128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/2019091920130996.jpg",
        "price": "5899",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 白色 128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190926164950757.jpg",
        "price": "5850",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 黄色 256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/2019092616500233.jpg",
        "price": "6450",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 黑色 256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190911103416335.jpg",
        "price": "6550",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 绿色 64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190919201245516.jpg",
        "price": "5299",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 红色 128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190911103914196.jpg",
        "price": "5899",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 黄色 128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/2019092616500233.jpg",
        "price": "5850",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 绿色 128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190919201251769.jpg",
        "price": "5850",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 白色 256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190926164950757.jpg",
        "price": "6550",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 绿色 256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190919201254844.jpg",
        "price": "6550",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 紫色 64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/2019091920130996.jpg",
        "price": "5260",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 Pro 全网通 暗夜绿色 64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191009174152488.jpg",
        "price": "8399",
        "title": "【Pro 如其名】突破性的三摄系统，A13仿生实时处理",
        "commentCount": 1290,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"后置三摄\",\"标配18W快充\"]"
    }, {
        "name": "Apple iPhone 11 全网通 红色 64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190911103914196.jpg",
        "price": "5260",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "Apple iPhone 11 全网通 黑色 128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190911103416335.jpg",
        "price": "5850",
        "title": "【一切都刚刚好】全新双摄系统取景，A13仿生实时处理",
        "commentCount": 12150,
        "tag": "[\"双卡双待\",\"A13仿生芯片\",\"IP68防水\"]"
    }, {
        "name": "华为 Mate 30 全网通5G版 亮黑色 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200103110542005.jpg",
        "price": "4999",
        "title": "【重构想象】搭载华为首款旗舰 5G SoC 芯片，4000万超感光徕卡影像",
        "commentCount": 1949,
        "tag": "[\"麒麟990 5G\",\"4000万超感光徕卡三摄\",\"OLED全面屏\"]"
    }, {
        "name": "华为 Mate 30 Pro 全网通5G版 亮黑色 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191209195431227.jpg",
        "price": "6899",
        "title": "【重构想象】搭载华为首款旗舰 5G SoC 芯片，麒麟990",
        "commentCount": 2241,
        "tag": "[\"海思麒麟990 5G\",\"后置徕卡四摄\",\"超曲面OLED环幕屏\"]"
    }, {
        "name": "华为 nova 6 全网通5G版 亮黑色 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200113170650731.jpg",
        "price": "3799",
        "title": "105°前置广角双摄，超感光暗拍，海思麒麟990+巴龙5000",
        "commentCount": 593,
        "tag": "[\"海思麒麟990+巴龙5000\",\"5G双模\",\"105°前置广角双摄\"]"
    }, {
        "name": "华为 畅享10 全网通版 幻夜黑 4GB+64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200103110521014.jpg",
        "price": "1099",
        "title": "官网最高直降100，6.39英寸极点全面屏，4800万超清夜景，4000mAh大电池",
        "commentCount": 1107,
        "tag": "[\"AI双摄\",\"海思麒麟710F\",\"手持超级夜景\"]"
    }, {
        "name": "华为 P30 全网通版 天空之境 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200103110442983.jpg",
        "price": "3388",
        "title": "【影像之美】后置徕卡三摄,麒麟980智慧大脑",
        "commentCount": 3712,
        "tag": "[\"30倍变焦\",\"屏内指纹识别\",\"麒麟980\"]"
    }, {
        "name": "华为 nova 6 SE 全网通版 幻夜黑 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200103110352813.jpg",
        "price": "2199",
        "title": "全场景AI四摄，手持超级夜景，4200mAh大电池",
        "commentCount": 183,
        "tag": "[\"4800万AI四摄\",\"40W超级快充\",\"海思麒麟810\"]"
    }, {
        "name": "华为 Mate 30 全网通4G版 亮黑色 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200103110611382.jpg",
        "price": "3999",
        "title": "【重构想象】麒麟990，4000万超感光徕卡影像，OLED全面屏",
        "commentCount": 2850,
        "tag": "[\"海思麒麟990\",\"4000万超感光徕卡三摄\",\"OLED全面屏\"]"
    }, {
        "name": "华为 nova 5 Pro 全网通版 亮黑色 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200103110315981.jpg",
        "price": "2399",
        "title": "【你比夜色更美】3200万人像超夜景，4800万AI四摄",
        "commentCount": 5160,
        "tag": "[\"40W超级快充\",\"屏幕指纹\",\"后置四摄\"]"
    }, {
        "name": "华为 畅享10 Plus 全网通版 翡冷翠 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200103110625757.jpg",
        "price": "1599",
        "title": "【前置悬浮式镜头】海思麒麟710F，4800万像素主摄，4000mAh电池",
        "commentCount": 1902,
        "tag": "[\"海思麒麟710F\",\"4800万像素主摄\",\"悬浮式自动升降镜头\"]"
    }, {
        "name": "华为 Mate 20 X 全网通5G版 宝石蓝 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200113170328634.jpg",
        "price": "4299",
        "title": "获首张中国5G进网许可证的5G双模（同时支持SA和NSA组网架构）全网通手机",
        "commentCount": 136,
        "tag": "[\"5G旗舰芯片\",\"5G双模全网通\",\"40W超级快充\"]"
    }, {
        "name": "华为 nova 5i Pro 全网通版 翡冷翠 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200102104830333.jpg",
        "price": "1899",
        "title": "【3200万人像超级夜景】6.26英寸极点全面屏，海思麒麟810",
        "commentCount": 670,
        "tag": "[\"面部识别解锁\",\"后置四摄\",\"全面屏\",\"6.26英寸极点全面屏\"]"
    }, {
        "name": "华为 畅享 10S 全网通版 天空之境 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200103110502175.jpg",
        "price": "1699",
        "title": "炫彩OLED屏幕指纹，4800万超广角三摄，4000mAh大电池",
        "commentCount": 297,
        "tag": "[\"4800万超广角AI三摄\",\"4000mAh超强续航\"]"
    }, {
        "name": "华为 Mate 20 全网通版 极光色 6GB+64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200106180106389.jpg",
        "price": "2399",
        "title": "【智慧新高度】后置徕卡三摄，海思麒麟980",
        "commentCount": 6940,
        "tag": "[\"6.53英寸\",\"面部识别\",\"后置三摄\"]"
    }, {
        "name": "华为 nova 6 全网通4G版 亮黑色 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200113170248481.jpg",
        "price": "2999",
        "title": "105°前置广角双摄，超感光暗拍，麒麟990芯片",
        "commentCount": 207,
        "tag": "[\"105°前置广角双摄\",\"超感光暗拍\",\"麒麟990芯片\"]"
    }, {
        "name": "华为 P30 Pro 全网通版 天空之境 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200113170313046.jpg",
        "price": "4488",
        "title": "【影像之美】超感光徕卡四摄，麒麟980智慧大脑",
        "commentCount": 3528,
        "tag": "[\"50倍数字变焦\",\"屏内指纹\",\"防水防尘IP68\"]"
    }, {
        "name": "华为 nova 4e 全网通版 幻夜黑 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200106180130966.jpg",
        "price": "1260",
        "title": "【超广角AI三摄】海思麒麟710，6.15英寸珍珠全面屏",
        "commentCount": 2876,
        "tag": "[\"3200万立体美颜\",\"AI超广角三摄\",\"3D曲面玻璃\"]"
    }, {
        "name": "华为 畅享9 全网通高配版 极光蓝 4GB+64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200102104955715.jpg",
        "price": "899",
        "title": "【大电池 强劲续航】高通骁龙450，千元珍珠屏，AI长续航",
        "commentCount": 4103,
        "tag": "[\"AI智慧双摄\",\"4000mAh大电池\",\"全面屏\"]"
    }, {
        "name": "华为 畅享9e 全网通版 宝石蓝 3GB+64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200102105018672.jpg",
        "price": "799",
        "title": "【火热销售】6.09英寸高清珍珠屏，大存储大音量，出彩夜拍",
        "commentCount": 837,
        "tag": "[\"64GB大内存\",\"后置1300万像素\",\"12nm八核处理器\"]"
    }, {
        "name": "华为 Mate 30 全网通5G版 罗兰紫 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191106094757296.jpg",
        "price": "4999",
        "title": "【重构想象】搭载华为首款旗舰 5G SoC 芯片，4000万超感光徕卡影像",
        "commentCount": 1949,
        "tag": "[\"麒麟990 5G\",\"4000万超感光徕卡三摄\",\"OLED全面屏\"]"
    }, {
        "name": "华为 Mate 30 全网通5G版 亮黑色 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191106094800559.jpg",
        "price": "5499",
        "title": "【重构想象】搭载华为首款旗舰 5G SoC 芯片，4000万超感光徕卡影像",
        "commentCount": 1949,
        "tag": "[\"麒麟990 5G\",\"4000万超感光徕卡三摄\",\"OLED全面屏\"]"
    }, {
        "name": "红米 Redmi K30 全网通4G版 深海微光 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20200102104021265.jpg",
        "price": "2199",
        "title": "6400万前后六摄,120Hz流速屏",
        "commentCount": 152,
        "tag": "[\"6400万前后六摄\",\"120Hz流速屏\"]"
    }, {
        "name": "小米 CC9 Pro 全网通版 暗夜魅影 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191105155701736.jpg",
        "price": "2699",
        "title": "一亿像素，五摄四闪，双光学防抖拍照",
        "commentCount": 212,
        "tag": "[\"5260mAh\",\"高通骁龙730G\",\"屏下指纹\"]"
    }, {
        "name": "小米9 Pro 全网通5G版 梦之白 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190923100026167.jpg",
        "price": "3750",
        "title": "【快的不只是5G】40W有线+30W无线+10W无线反充，VC液冷散热，4800万三摄",
        "commentCount": 342,
        "tag": "[\"30W无线闪充\",\"骁龙855Plus\",\"40W超级有线闪充\"]"
    }, {
        "name": "小米 CC9 Pro 全网通版 冰雪极光 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191105163202466.jpg",
        "price": "3199",
        "title": "一亿像素，五摄四闪，双光学防抖拍照",
        "commentCount": 212,
        "tag": "[\"5260mAh\",\"高通骁龙730G\",\"屏下指纹\"]"
    }, {
        "name": "小米9 Pro 全网通5G版 钛银黑 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190924152507337.jpg",
        "price": "3750",
        "title": "【快的不只是5G】40W有线+30W无线+10W无线反充，VC液冷散热，4800万三摄",
        "commentCount": 342,
        "tag": "[\"30W无线闪充\",\"骁龙855Plus\",\"40W超级有线闪充\"]"
    }, {
        "name": "小米 CC9 Pro 全网通版 魔法绿镜 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191105163212236.jpg",
        "price": "3199",
        "title": "一亿像素，五摄四闪，双光学防抖拍照",
        "commentCount": 212,
        "tag": "[\"5260mAh\",\"高通骁龙730G\",\"屏下指纹\"]"
    }, {
        "name": "小米 CC9 Pro 全网通版 冰雪极光 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191105163142568.jpg",
        "price": "2699",
        "title": "一亿像素，五摄四闪，双光学防抖拍照",
        "commentCount": 212,
        "tag": "[\"5260mAh\",\"高通骁龙730G\",\"屏下指纹\"]"
    }, {
        "name": "小米 CC9 Pro 全网通版 暗夜魅影 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191105163207322.jpg",
        "price": "3199",
        "title": "一亿像素，五摄四闪，双光学防抖拍照",
        "commentCount": 212,
        "tag": "[\"5260mAh\",\"高通骁龙730G\",\"屏下指纹\"]"
    }, {
        "name": "小米 CC9 Pro 全网通版 魔法绿镜 8GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191105163138745.jpg",
        "price": "2699",
        "title": "一亿像素，五摄四闪，双光学防抖拍照",
        "commentCount": 212,
        "tag": "[\"5260mAh\",\"高通骁龙730G\",\"屏下指纹\"]"
    }, {
        "name": "小米 MIX Alpha 黑色 12GB+512GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190924203838880.jpg",
        "price": "19999",
        "title": "创新环绕屏，极具未来感的智能交互体验 ，1亿像素超高清相机，超大感光元件",
        "commentCount": 0,
        "tag": "[\"纳米硅基锂离子4050mAh电池\",\"40W超级快充\"]"
    }, {
        "name": "小米 CC9 全网通版 暗夜王子 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190702213748654.jpg",
        "price": "1599",
        "title": "【前后双旗舰相机】前置3200万自拍，索尼4800万超广角三摄",
        "commentCount": 362,
        "tag": "[\"4030mAh大电量\",\"多色炫彩轻薄机身\"]"
    }, {
        "name": "小米 CC9 全网通版 深蓝星球 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190702213751404.jpg",
        "price": "1599",
        "title": "【前后双旗舰相机】前置3200万自拍，索尼4800万超广角三摄",
        "commentCount": 362,
        "tag": "[\"4030mAh大电量\",\"多色炫彩轻薄机身\"]"
    }, {
        "name": "红米 Redmi K30 全网通5G版 时光独白 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191210171423742.jpg",
        "price": "2899",
        "title": "双模5G，6400万前后六摄，120Hz流速屏",
        "commentCount": 9,
        "tag": "[\"5G双模全网通\",\"30W极速闪充\",\"6400万前后六摄\"]"
    }, {
        "name": "红米 Redmi K30 全网通5G版 深海微光 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191210165454034.jpg",
        "price": "2899",
        "title": "双模5G，6400万前后六摄，120Hz流速屏",
        "commentCount": 9,
        "tag": "[\"5G双模全网通\",\"30W极速闪充\",\"6400万前后六摄\"]"
    }, {
        "name": "小米 CC9e 全网通版 白色恋人 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190702221505727.jpg",
        "price": "1230",
        "title": "【前后双旗舰相机】前置3200万自拍，索尼4800万超广角三摄",
        "commentCount": 268,
        "tag": "[\"4030mAh大电量\",\"多色炫彩轻薄机身\"]"
    }, {
        "name": "红米 Redmi K30 全网通5G版 紫玉幻境 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191210165450210.jpg",
        "price": "2899",
        "title": "双模5G，6400万前后六摄，120Hz流速屏",
        "commentCount": 9,
        "tag": "[\"5G双模全网通\",\"30W极速闪充\",\"6400万前后六摄\"]"
    }, {
        "name": "红米 Redmi K30 全网通5G版 花影惊鸿 8GB+256GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20191210165447304.jpg",
        "price": "2899",
        "title": "双模5G，6400万前后六摄，120Hz流速屏",
        "commentCount": 9,
        "tag": "[\"5G双模全网通\",\"30W极速闪充\",\"6400万前后六摄\"]"
    }, {
        "name": "小米 CC9 全网通版 白色恋人 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190702213745831.jpg",
        "price": "1630",
        "title": "【前后双旗舰相机】前置3200万自拍，索尼4800万超广角三摄",
        "commentCount": 362,
        "tag": "[\"4030mAh大电量\",\"多色炫彩轻薄机身\"]"
    }, {
        "name": "小米 CC9e 全网通版 深蓝星球 6GB+64GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190702221452870.jpg",
        "price": "1050",
        "title": "【前后双旗舰相机】前置3200万自拍，索尼4800万超广角三摄",
        "commentCount": 268,
        "tag": "[\"4030mAh大电量\",\"多色炫彩轻薄机身\"]"
    }, {
        "name": "小米 CC9e 全网通版 深蓝星球 6GB+128GB ",
        "src": "https://img2.ch999img.com/pic/product/440x440/20190702221459321.jpg",
        "price": "1230",
        "title": "【前后双旗舰相机】前置3200万自拍，索尼4800万超广角三摄",
        "commentCount": 268,
        "tag": "[\"4030mAh大电量\",\"多色炫彩轻薄机身\"]"
    }];

    for (let i = 0; i < arr.length; i++) {
        let name = arr[i].name;
        let src = arr[i].src;
        let price = arr[i].price;
        let title = arr[i].title;
        let commentCount = arr[i].commentCount;
        let tag = arr[i].tag;
        let sql = `INSERT INTO goods (good_id, src, title, price, name, tag, commentCount) 
        VALUES (null, '${src}', '${title}', ${price}, '${name}', '${tag}', '${commentCount}')`
        let data = await query(sql);
    }
    res.send(arr)
});
module.exports = Router;